import { assetManager, ImageAsset, sp, Texture2D, url } from "cc";
import * as fgui from "fairygui-cc";
import UrlEnum from "./UrlEnum";
export default class UICore {
    public static compressIgnoreList: Array<string> = [];

    /**
     * 加载资源列表
     */
    public static loadPackageList(list: Array<string>, callback?: Function): void {
        const url: string = list.pop();
        if (!url) {
            callback();
            return;
        }
        if (this.compressIgnoreList.indexOf(url) > -1) {
            UICore.loadPackageList(list, callback);
            return;
        }
        fgui.UIPackage.loadPackage(`UI/${url}`, (error, pkg: fgui.UIPackage) => {
            this.compressIgnoreList.push(url);
            UICore.loadPackageList(list, callback);
        })
    }
    /**
    * 创建对象
    */
    public static createObject(pkgName: string, resName: string, userClass?: any): fgui.GObject {
        return fgui.UIPackage.createObject(pkgName, resName, userClass);
    }
    /**获取指定包下指定资源的地址 */
    public static getURL(pkgName: string, resName: string): string {
        return fgui.UIPackage.getItemURL(pkgName, resName);
    }
    /**注册扩展 */
    public static registerExtension(pkgName: string, resName: string, userClass: any): void {
        fgui.UIObjectFactory.setExtension(UICore.getURL(pkgName, resName), userClass);
    }
}